<?php
namespace Admin\Controller;

class GameTeamMemberController extends BaseManageController {
    /**
    *控制操作的模型表
    */
    protected $modelName = 'Common/GameTeamMember';

    /**
    *删除类型的设置 true|直接删除， false|设置数据状态
    */  
    protected $is_del   = true;

    /**
    *操作index的前置操作
    *---设置数据筛选条件---
    */
    public function _before_index()
    {
        $team_id = I('team_id', 0, 'intval');
        if (!$team_id) {
            $this->error('战队信息错误');
        }
        $this->assign('team_id', $team_id);
        $map = array();//筛选条件
        $map['status'] = array('egt',0);
        $map['team_id'] = $team_id;

        $this->name = $name = trim(I('get.name', '', 'strip_tags'));
        if($name){
            $map['name']    =   array('like', (string)$name);
        }
        $this->where = $map;

        $this->sort = 'sort asc';
    }

    public function sort()
    {
        if (IS_POST) {
            $team_id = I('request.team_id', 0, 'intval');
            if (!$team_id) {
                $this->error('战队信息错误');
            }
            $sort_list = I('sort');
            if (is_array($sort_list)) {
                foreach ($sort_list as $key => $value) {
                    service('GameTeamMember')->save([
                        'id' => $key,
                        'sort' => intval($value)
                    ]);
                }
                $this->success('操作成功!', U('GameTeamMember/index', ['team_id' => $team_id]));
            }
        }
    }

    public function _before_add()
    {
        $team_id = I('team_id', 0, 'intval');
        if (!$team_id) {
            $this->error('战队信息错误');
        }
        $this->assign('team_id', $team_id);
    }

    public function _before_edit()
    {
        $team_id = I('team_id', 0, 'intval');
        if (!$team_id) {
            $this->error('战队信息错误');
        }
        $this->assign('team_id', $team_id);
    }
}